package com.thread.www;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by 27340 on 2017/3/23.
 */
public class BlockingQueueTest {
    public static void main(String[] args) throws Exception{
        final BlockingQueue<String> bq1 = new LinkedBlockingQueue<String>(16);
        final BlockingQueue<String> bq = new ArrayBlockingQueue<String>(16);
        for(int i=0;i<4;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    while(true){
                        try{
                            String log = bq.take();
                            parseLog(log);
                        } catch (Exception e){

                        }
                    }
                }
            }).start();
        }
        for(int i=0;i<16;i++){
            String log = (i+1) + "---->";
            bq.put(log);
        }
    }
    public static void parseLog(String log){
        System.out.println(log + System.currentTimeMillis());
        try{
            Thread.sleep(1000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
